
// const cloud = require('wx-server-sdk')
 
// cloud.init();
 
// // 云函数入口函数
// exports.main = (event) => {
//   console.log(event);
//   return cloud.openapi.security
//     .imgSecCheck({
//       media: {
//         contentType: 'image/png/jpg/jpeg',
//         value: event.img
//       }
//     })
//     .then(result => {
//       return result;
//     })
//     .catch(err => {
//       return err;
//     })
// }
const cloud = require("wx-server-sdk")
cloud.init() 

exports.main = async (event, context) => {
  const { value } = event;
  try {
      const res = await cloud.openapi.security.imgSecCheck({
        media: {
        header: {
        "Content-Type": "application/octet-stream"},
        contentType: "image/png/jpg/jpeg",
        value: Buffer.from(value)
      }
    })
    return res;
  } catch (err) {
    return err;
  }
}